﻿@using VocaDb.Web.Helpers
@using System.Web.Optimization
@using VocaDb.Web.Resources.Domain
@inherits VocaDb.Web.Code.VocaDbPage

@{
	var searchObjectType = PageProperties.GlobalSearchType;
}

<!-- Common scripts -->
@Scripts.Render("~/bundles/shared/libs", "~/bundles/shared/jqui", "~/bundles/VocaDB", "~/bundles/shared/common")

@if (PageProperties.AddMainScripts) {
	@Scripts.Render("~/bundles/shared/main")
}

<script type="text/javascript">

    var baseAddress = '@RootPath';

    vdb = vdb || {};
    vdb.values = vdb.values || {};
    vdb.values.hostAddress = '@UrlMapper.HostAddress';
	vdb.values.baseAddress = baseAddress;
	vdb.values.languagePreference = @((int)Login.Manager.LanguagePreference);
	vdb.values.isLoggedIn = @ToJS(UserContext.IsLoggedIn);
	vdb.values.uiLanguage = @ToJS(UICulture);
    vdb.resources = vdb.resources || {};
    var urlMapper = new vdb.UrlMapper(baseAddress);

    vdb.resources.shared = {
    	reportSent: @ToJS(AjaxRes.SharedStrings.ReportSent)
	};

    vdb.ui.initAll(@ToJS(AjaxRes.SharedStrings.ThanksForRating));

    var entryReportRepository = new vdb.repositories.EntryReportRepository(urlMapper);
    var userRepository = new vdb.repositories.UserRepository(urlMapper, @UserContext.LoggedUserId);

    var entryTypeTranslations = @ResourceHelpers.ToJSON(EntryTypeNames.ResourceManager);
    var topBarData = @Html.Raw(JsonHelpers.Serialize(new {
		searchObjectType = searchObjectType.ToString()
	}));
	var hasUnreadMessages = @ToJS(Login.Manager.IsLoggedIn && Login.User.UnreadMessagesCount > 0);
	var unreadMessagesCount = @(Login.Manager.IsLoggedIn ? Login.User.UnreadMessagesCount : 0);
	var getNewReportCount = @ToJS(Login.CanManageEntryReports);

    var topBarViewModel = new vdb.viewModels.TopBarViewModel(
        entryTypeTranslations, topBarData.searchObjectType, "", unreadMessagesCount,
	    getNewReportCount, entryReportRepository, userRepository);

    var topBar = $("#topBar")[0];
	if (topBar) {
		ko.applyBindings(topBarViewModel, $("#topBar")[0]);
	}

</script>
